/* 全局样式 */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: #f5f5f5;
    height: 100vh;
    overflow: hidden;
}

/* 工具栏 */
.toolbar {
    background: white;
    border-bottom: 1px solid #e0e0e0;
    padding: 0.5rem 1rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    height: 60px;
}

.toolbar-left,
.toolbar-center,
.toolbar-right {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.tool-btn {
    background: #f8f9fa;
    border: 1px solid #dee2e6;
    padding: 0.5rem 1rem;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.9rem;
    transition: all 0.2s ease;
}

.tool-btn:hover {
    background: #e9ecef;
    border-color: #adb5bd;
}

.tool-btn:active {
    transform: translateY(1px);
}

.page-input {
    width: 80px;
    padding: 0.5rem;
    border: 1px solid #dee2e6;
    border-radius: 6px;
    text-align: center;
}

#fileName {
    font-size: 1.2rem;
    color: #333;
    margin-left: 1rem;
}

#pageInfo {
    font-size: 0.9rem;
    color: #666;
    margin: 0 1rem;
}

#zoomLevel {
    font-size: 0.9rem;
    color: #666;
    min-width: 50px;
    text-align: center;
}

/* 主要内容区域 */
.main-content {
    display: flex;
    justify-content: center;
    height: calc(100vh - 60px);
    background: #e0e0e0;
    padding: 10px;
}

/* 文本选择样式 */
.textLayer {
    position: absolute;
    left: 0;
    top: 0;
    right: 0;
    bottom: 0;
    overflow: hidden;
    opacity: 0.01; /* 几乎完全透明 */
    line-height: 1.0;
    z-index: 2;
}

.textLayer div {
    color: transparent;
    position: absolute;
    white-space: pre;
    cursor: text;
    user-select: text;
    -webkit-user-select: text;
    -moz-user-select: text;
    -ms-user-select: text;
    transform-origin: 0% 0%;
    pointer-events: auto;
}

.textLayer div::selection {
    background: rgba(0, 123, 255, 0.4);
}

.textLayer div::-moz-selection {
    background: rgba(0, 123, 255, 0.4);
}

/* 选择文本时的视觉效果 */
.textLayer div::-webkit-selection {
    background: rgba(0, 123, 255, 0.4);
}

/* 左侧标注面板 */
.annotation-panel {
    background: white;
    display: flex;
    flex-direction: column;
    border-right: 1px solid #e0e0e0;
}

.panel-header {
    padding: 1rem;
    border-bottom: 1px solid #e0e0e0;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.panel-header h3 {
    color: #333;
    font-size: 1rem;
}

.add-btn {
    background: #007bff;
    color: white;
    border: none;
    padding: 0.5rem 1rem;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.8rem;
    transition: background 0.2s ease;
}

.add-btn:hover {
    background: #0056b3;
}

.annotation-list {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
}

.annotation-item {
    background: #f8f9fa;
    border: 1px solid #e9ecef;
    border-radius: 8px;
    padding: 1rem;
    margin-bottom: 1rem;
    cursor: pointer;
    transition: all 0.2s ease;
}

.annotation-item:hover {
    background: #e9ecef;
    transform: translateY(-1px);
}

.annotation-item.selected {
    border-color: #007bff;
    background: #e3f2fd;
}

.annotation-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.5rem;
}

.annotation-type {
    font-size: 0.8rem;
    padding: 0.2rem 0.5rem;
    border-radius: 4px;
    color: white;
}

.annotation-type.highlight {
    background: #ffc107;
}

.annotation-type.underline {
    background: #17a2b8;
}

.annotation-type.note {
    background: #28a745;
}

.annotation-type.question {
    background: #dc3545;
}

.annotation-page {
    font-size: 0.8rem;
    color: #666;
}

.annotation-content {
    font-size: 0.9rem;
    color: #333;
    line-height: 1.4;
}

/* PDF容器 */
.pdf-container {
    background: #f5f5f5;
    position: relative;
    overflow: auto;
    width: 100%;
    max-width: 1200px;
    height: 100%;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.pdf-viewer {
    display: flex;
    justify-content: center;
    align-items: flex-start;
    padding: 1rem;
    min-height: 100%;
}

#pdfCanvas {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    background: white;
    max-width: 100%;
    max-height: 100%;
}

/* 加载指示器 */
.loading {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    text-align: center;
    color: #666;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 4px solid #f3f3f3;
    border-top: 4px solid #007bff;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 1rem;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* 错误消息 */
.error-message {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    text-align: center;
    color: #dc3545;
}

.error-message button {
    background: #dc3545;
    color: white;
    border: none;
    padding: 0.5rem 1rem;
    border-radius: 6px;
    cursor: pointer;
    margin-top: 1rem;
}

/* 右侧AI面板 */
.ai-panel {
    background: white;
    display: flex;
    flex-direction: column;
    border-left: 1px solid #e0e0e0;
}

.ai-content {
    flex: 1;
    padding: 1rem;
    overflow-y: auto;
}

.welcome-message {
    text-align: center;
    color: #666;
    padding: 2rem 1rem;
}

.welcome-message h4 {
    color: #333;
    margin-bottom: 1rem;
}

.analyze-btn {
    background: #28a745;
    color: white;
    border: none;
    padding: 0.5rem 1rem;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.8rem;
    transition: background 0.2s ease;
}

.analyze-btn:hover {
    background: #218838;
}

.analyze-btn:disabled {
    background: #6c757d;
    cursor: not-allowed;
}

.analysis-result {
    margin-top: 1rem;
    padding: 1rem;
    background: #f8f9fa;
    border-radius: 8px;
    border-left: 4px solid #007bff;
}

.analysis-result h4 {
    color: #333;
    margin-bottom: 0.5rem;
}

.analysis-result p {
    color: #666;
    line-height: 1.5;
    margin-bottom: 0.5rem;
}

.analysis-result ul {
    margin: 0.5rem 0;
    padding-left: 1.5rem;
}

.analysis-result li {
    color: #666;
    margin-bottom: 0.3rem;
}

/* 模态框 */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(5px);
}

.modal-content {
    background-color: white;
    margin: 10% auto;
    padding: 0;
    border-radius: 12px;
    width: 90%;
    max-width: 500px;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.2);
    overflow: hidden;
}

.modal-header {
    background: #f8f9fa;
    padding: 1rem;
    border-bottom: 1px solid #e9ecef;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-header h3 {
    color: #333;
    font-size: 1.1rem;
}

.close {
    font-size: 1.5rem;
    cursor: pointer;
    color: #666;
    transition: color 0.2s ease;
}

.close:hover {
    color: #333;
}

#annotationForm {
    padding: 1.5rem;
}

.form-group {
    margin-bottom: 1rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    color: #333;
    font-weight: 500;
}

.form-group select,
.form-group textarea {
    width: 100%;
    padding: 0.5rem;
    border: 1px solid #dee2e6;
    border-radius: 6px;
    font-family: inherit;
    font-size: 0.9rem;
}

.form-group textarea {
    resize: vertical;
    min-height: 80px;
}

.form-group input[type="color"] {
    width: 60px;
    height: 40px;
    border: none;
    border-radius: 6px;
    cursor: pointer;
}

.form-actions {
    display: flex;
    gap: 1rem;
    justify-content: flex-end;
    margin-top: 1.5rem;
}

.cancel-btn {
    background: #6c757d;
    color: white;
    border: none;
    padding: 0.5rem 1rem;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.9rem;
    transition: background 0.2s ease;
}

.cancel-btn:hover {
    background: #5a6268;
}

.save-btn {
    background: #007bff;
    color: white;
    border: none;
    padding: 0.5rem 1rem;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.9rem;
    transition: background 0.2s ease;
}

.save-btn:hover {
    background: #0056b3;
}

/* 文本选择样式 */
::selection {
    background: rgba(0, 123, 255, 0.3);
}

/* 响应式设计 */
@media (max-width: 1200px) {
    .main-content {
        grid-template-columns: 200px 1fr 250px;
    }
}

@media (max-width: 768px) {
    .main-content {
        grid-template-columns: 1fr;
        grid-template-rows: auto 1fr auto;
    }
    
    .annotation-panel,
    .ai-panel {
        position: fixed;
        top: 60px;
        width: 100%;
        height: calc(100vh - 60px);
        z-index: 100;
        transform: translateX(-100%);
        transition: transform 0.3s ease;
    }
    
    .annotation-panel.active,
    .ai-panel.active {
        transform: translateX(0);
    }
    
    .toolbar {
        flex-direction: column;
        height: auto;
        padding: 1rem;
    }
    
    .toolbar-left,
    .toolbar-center,
    .toolbar-right {
        width: 100%;
        justify-content: center;
        margin-bottom: 0.5rem;
    }
}

/* OCR状态提示样式 */
.ocr-status {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(0, 0, 0, 0.8);
    color: white;
    padding: 20px 30px;
    border-radius: 8px;
    z-index: 1000;
    font-size: 16px;
    text-align: center;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.ocr-status.loading::before {
    content: '';
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-top: 2px solid white;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-right: 10px;
    vertical-align: middle;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.ocr-tips {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: white;
    border: 1px solid #ddd;
    border-radius: 8px;
    padding: 20px;
    max-width: 400px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    z-index: 1001;
}

.ocr-tips h4 {
    margin-top: 0;
    color: #333;
    border-bottom: 1px solid #eee;
    padding-bottom: 10px;
}

.ocr-tips ul {
    margin: 15px 0;
    padding-left: 20px;
}

.ocr-tips li {
    margin: 8px 0;
    color: #666;
}

.ocr-tips button {
    background: #007bff;
    color: white;
    border: none;
    padding: 8px 16px;
    border-radius: 4px;
    cursor: pointer;
    float: right;
}

.ocr-tips button:hover {
    background: #0056b3;
}

/* 文本层样式 */
#text-layer {
    user-select: text;
    -webkit-user-select: text;
    -moz-user-select: text;
    -ms-user-select: text;
}

#text-layer div {
    font-family: inherit;
    font-size: inherit;
    line-height: inherit;
}

/* 工具按钮状态 */
.tool-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.tool-btn:hover:not(:disabled) {
    background-color: #f0f0f0;
    transform: translateY(-1px);
}

/* 复制通知 */
.copy-notification {
    position: fixed;
    top: 20px;
    right: 20px;
    background: #28a745;
    color: white;
    padding: 12px 20px;
    border-radius: 4px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
    z-index: 1000;
    animation: slideInRight 0.3s ease-out;
}

@keyframes slideInRight {
    from {
        transform: translateX(100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}
